<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="mydiv">
    <input type="file" id="file" multiple>
    <input type="button" value="上传" onclick="upload()">
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
    $(function () {
        console.log("页面加载完成事件")
    })

    function upload() {
        console.log($("#file"))
        // JQuery转js对象
        console.log($("#file")[0])
        debugger
        const file = $("#file")[0].files;

        const formData = new FormData();
        const a = 5;
        for (let i = 0; i < file.length; i++) {
            formData.append("file", file[i]);
        }
        formData.append("username", "zoe");
        $.ajax({
            type: 'post',
            url: '/multipart',
            processData: false,
            contentType: false,
            data: formData,
            success: function (res) {
                $(".mydiv").html(res);
            }
        })
    }
</script>
</html>